package com.dk.data;

import com.dk.enums.ResultEnum;

public class R<T> {


    private  Integer code;  //表示状态码比如10000表示成功，9999表示失败
    private String message;
    private T data;

    //通用成功方法
    public static R ok(){
        R r=new R(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMessage());
        return r;
    }

    //通用失败方法
    //通用成功方法
    public static R error(){
        R r=new R(ResultEnum.ERROR.getCode(),ResultEnum.ERROR.getMessage());
        return r;
    }

    //除了成功失败以外其他状态调用方法
    public static R response(ResultEnum resultEnum){
        R r=new R(resultEnum.getCode(),resultEnum.getMessage());
        return r;
    }


    public R(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public R() {
    }

    public R(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public R setData(T data) {
        this.data = data;
        return  this;
    }
}
